/*
  学习目标：hooks补充-useRef
  作用: 创建ref对象 
  等同于: React.createRef
  场景:
    1. 获取dom
    2. 获取组件实例对象
    3. 💥可以保存任意不需要渲染的数据
  
*/

import { useRef } from 'react';
import { useEffect } from 'react';

export default function App() {
  const timerIdRef = useRef();

  console.log('timerIdRef  ----->  ', timerIdRef);

  useEffect(() => {
    timerIdRef.current = setInterval(() => {
      console.log('定时器在跑  ----->  ');
    }, 500);
  }, []);

  return (
    <>
      <button
        onClick={() => {
          // console.log('timerIdRef.current  ----->  ', timerIdRef.current);
          clearInterval(timerIdRef.current);
        }}
      >
        点我停止定时器
      </button>
    </>
  );
}
